package com.email.controller;

import com.email.service.MailService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EmailController {

    @Autowired
    MailService mailService;

    @GetMapping("sendEmail")
    Integer sendEmail(@RequestParam("to") String to, @RequestParam("subject") String subject, @RequestParam("content") String content) {
        LoggerFactory.getLogger(this.getClass()).info(to, subject, content + "+++++++++++++++++++++++++++++++++++++");
        try {
            mailService.sendSimpleMail(to, subject, content);
        } catch (Exception e) {
            e.printStackTrace();
            return -1;
        }
        return 0;
    }
}
